package cn.edu.neu.lab603.math

import breeze.linalg._
import breeze.numerics.pow
import breeze.stats.mean

/** 根据给定的资源向量确定资源占比权重。
  *
  * Created by yfwz100 on 2016/10/17.
  */
object ResRank {

  def apply(res: DenseMatrix[Double]): DenseVector[Double] = {
    val normRes = res(::, *) / sum(res(*, ::))
    val p = -1
    val s = normRes(::, *).map { r =>
      pow(mean(r.map(pow(_, p))), p)
    }
    s.t / sum(s) // normalize the result.
  }
}
